/*!
 Temelia - Scapegoat tree performance tests.

 Copyright (C) 2008 Ceata (http://cod.ceata.org/proiecte/temelia).

 @author Dascalu Laurentiu

 This program is free software; you can redistribute it and
 modify it under the terms of the GNU General Public License
 as published by the Free Software Foundation; either version 3
 of the License, or (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

#include "include/performance.hpp"
#include "include/testutil.hpp"

extern "C"
{
#include <temelia/scapegoat_tree.h>
}

static void temelia_scapegoat_tree_search(int n,
		scapegoat_tree_t scapegoat_tree)
{
	for (int i = 0; i < n; i++)
		scapegoat_tree_insert(scapegoat_tree, default_collection[i],
				int_compare, NULL);

	for (int i = 0; i < n; i++)
		scapegoat_tree_search(scapegoat_tree, default_collection[i],
				int_compare, NULL);

	scapegoat_tree_delete(scapegoat_tree);
}

static void temelia_scapegoat_tree_insert(int n,
		scapegoat_tree_t scapegoat_tree)
{
	for (int i = 0; i < n; i++)
		scapegoat_tree_insert(scapegoat_tree, default_collection[i],
				int_compare, NULL);
	scapegoat_tree_delete(scapegoat_tree);
}

static void temelia_scapegoat_tree_remove(int n,
		scapegoat_tree_t scapegoat_tree)
{
	for (int i = 0; i < n; i++)
		scapegoat_tree_insert(scapegoat_tree, default_collection[i],
				int_compare, NULL);

	for (int i = 0; i < n; i++)
		scapegoat_tree_remove(scapegoat_tree, default_collection[i],
				int_compare, NULL);

	scapegoat_tree_delete(scapegoat_tree);
}

static void temelia_scapegoat_tree_search_055(int n)
{
	temelia_scapegoat_tree_search(n, scapegoat_tree_new(0.55));
}

static void temelia_scapegoat_tree_insert_055(int n)
{
	temelia_scapegoat_tree_insert(n, scapegoat_tree_new(0.55));
}

static void temelia_scapegoat_tree_remove_055(int n)
{
	temelia_scapegoat_tree_remove(n, scapegoat_tree_new(0.55));
}

static void temelia_scapegoat_tree_search_070(int n)
{
	temelia_scapegoat_tree_search(n, scapegoat_tree_new(0.70));
}

static void temelia_scapegoat_tree_insert_070(int n)
{
	temelia_scapegoat_tree_insert(n, scapegoat_tree_new(0.70));
}

static void temelia_scapegoat_tree_remove_070(int n)
{
	temelia_scapegoat_tree_remove(n, scapegoat_tree_new(0.70));
}

void TemeliaPerformance::pt_scapegoat_tree(void)
{
	TestUnit testUnit("scapegoat_tree");

#ifndef CLUSTER_RUNNING
	ntests = 8;
#endif

	GENERATE_TEMELIA_TEST(testUnit, "insert_alfa_0.55", scapegoat_tree_insert_055);
	GENERATE_TEMELIA_TEST(testUnit, "search_alfa_0.55", scapegoat_tree_search_055);
	GENERATE_TEMELIA_TEST(testUnit, "remove_alfa_0.55", scapegoat_tree_remove_055);

	GENERATE_TEMELIA_TEST(testUnit, "insert_alfa_0.70", scapegoat_tree_insert_070);
	GENERATE_TEMELIA_TEST(testUnit, "search_alfa_0.70", scapegoat_tree_search_070);
	GENERATE_TEMELIA_TEST(testUnit, "remove_alfa_0.70", scapegoat_tree_remove_070);

	testUnit.write(fout);
}
